
@ECHO off
REM
REM Script to add a URL or site to the trusted location list
REM Last Updated: 11/2/05

if "%1" == "/?" GOTO Help
if "%1" == "" GOTO Help

SET LocationType=SharePoint
for /f "usebackq skip=3" %%i in (`%windir%\system32\cscript /nologo %windir%\system32\iisvdir.vbs /query "Office Server Web Services"`) do set variable=%%i
set sspname=%variable:~1%

:Arguments
if "%2" == "Unc" SET LocationType=Unc
if "%2" == "UNC" SET LocationType=Unc
if "%2" == "unc" SET LocationType=Unc

if EXIST "%commonprogramfiles%\Microsoft Shared Debug\web server extensions\12\BIN\stsadm.exe" (
     SET STSADM="%commonprogramfiles%\Microsoft Shared Debug\web server extensions\12\BIN\stsadm.exe"
)

if EXIST "%commonprogramfiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe" (
     SET STSADM="%commonprogramfiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"
)

if NOT EXIST %STSADM% (
    ECHO Error:  STSADM.EXE cannot be found in your system.
    GOTO Error
    )
ECHO.
ECHO Adding %1 to the Trusted Locations list ...
ECHO Type = %LocationType%
ECHO SSP Name = %sspname%
%STSADM% -o add-ecsfiletrustedlocation -ssp %sspname% -location %1 -includechildren true -locationtype %LocationType% -allowexternaldata dclandembedded -warnondatarefresh true
if NOT %ERRORLEVEL% == 0 (
        ECHO Error:  Error running stsAdm
        GOTO Error
        )
ECHO.
ECHO ********************************
ECHO %1 has been added
ECHO ********************************
ECHO.
PAUSE
GOTO End

:Error
ECHO.
ECHO ********************************
ECHO Failed!
ECHO ********************************
ECHO.
PAUSE
GOTO End

:Help
ECHO.
ECHO The command line syntax:
ECHO    AddTrustedFileLocation http://<servername>/<customsite>
ECHO    AddTrustedFileLocation \\<Servername>\<Foldername> unc
ECHO.
ECHO Examples:
ECHO    C:\AddTrustedFileLocation http://<servername>/<customsite>
ECHO    C:\AddTrustedFileLocation \\<Servername>\<Foldername> unc
PAUSE
GOTO End
:End